package hyperzsoft.triplea.game;

import android.app.Activity;
import android.content.Context;
import android.os.Bundle;
import android.view.LayoutInflater;
import android.widget.ArrayAdapter;
import android.widget.TableLayout;
import android.widget.TableRow;
import android.widget.TextView;

/*
 * This program is free software; you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation; either version 2 of the License, or
 * (at your option) any later version.
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 * You should have received a copy of the GNU General Public License
 * along with this program; if not, write to the Free Software
 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
 */

/*
 * GameRun.java
 *
 * Created on August 02, 2011, 14:11pm PST
 */

public class Main extends Activity {
   /** Called when the activity is first created. */
   @Override
   public void onCreate(Bundle savedInstanceState) {
      super.onCreate(savedInstanceState);
      this.setContentView(R.layout.main);

      //Player or AI selection setup
      loadPlayerSelection();
   }

   private void loadPlayerSelection() {
      TableRow tr;
      LayoutInflater vi = (LayoutInflater) getSystemService(Context.LAYOUT_INFLATER_SERVICE);
      TableLayout tl = (TableLayout)findViewById(R.id.players_select);

      for (int numPlayers = 0; numPlayers <= getResources().getInteger(R.integer.total_players); numPlayers++) {

         tr = (TableRow) vi.inflate(R.layout.player_selector, null);

         ((TextView) tr.getChildAt(0)).setText(getResources().getStringArray(R.array.player_types)[numPlayers]);
         CustomSpinner spinner = (CustomSpinner) tr.getChildAt(1);

         ArrayAdapter<CharSequence> adapter = ArrayAdapter.createFromResource(this, R.array.players,
                  R.layout.custom_spinner_item);

         adapter.setDropDownViewResource(R.layout.custom_spinner_dropdown_item);
         spinner.setAdapter(adapter);

         tl.addView(tr);
      }
   }
}